import { Store } from "iflux2";
import { domainList } from "webapi";
import { fromJS } from "immutable";
import OrderAcrtor from "./actor/order-actor";
import { LangingPageContent } from "./constant/action-type";
import initXSite from "../common/initOpenApi";

export default class AppStore extends Store {
  bindActor() {
    return [new OrderAcrtor()];
  }

  landingPage = async () => {
    try {
      const res = await domainList();
      this.dispatch(LangingPageContent.LANDING_PAGE, fromJS(res));
    } catch (err) {
      return Promise.reject(err);
    }
  };

  getActivatedPageInfo = () => {
    return initXSite().then(
      data => {
        data.PageService.getActivatedPageInfo().then(result => {
          this.dispatch(LangingPageContent.SET_PAGE_INFO, fromJS(result));
        });
      },
      err => {
        return Promise.reject(err);
      }
    );
  };
}
